<?php

namespace mpend\modules\user\controllers;

use Yii;
use mpend\components\Controller;
use mpend\modules\user\models\HistorySearch;

/**
 * 用户足迹接口
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class HistoryController extends Controller {

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            '*' => ['GET'],
            'clear' => ['POST'],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * 用户浏览的商品
     *
     * @return mixed
     * @throws \Throwable
     */
    public function actionIndex() {
        $model = new HistorySearch();
        $model->user_id = $this->uid;
        return $model->search();
    }

    /**
     * 清空
     *
     * @return mixed
     */
    public function actionClear() {
        HistorySearch::deleteAll(['user_id' => $this->uid]);
        return true;
    }

}
